
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Javascript教程 - 函数 - 小白AI.易名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="Javascript教程"><meta name="keywords" content="小白AI.易名,xiaobaiai.net,Javascript,入门,教程,博客">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="小白AI.易名">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="array.html" />
    
    
    <link rel="prev" href="object.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../../assets/images/apple-touch-icon.png'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../../assets/images/apple-touch-icon-120x120.png">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../../assets/images/apple-touch-icon-180x180.png">
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../basic/">
            
                <a href="../basic/">
            
                    
                    入门篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../basic/introduction.html">
            
                <a href="../basic/introduction.html">
            
                    
                    导论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../basic/history.html">
            
                <a href="../basic/history.html">
            
                    
                    历史
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../basic/grammar.html">
            
                <a href="../basic/grammar.html">
            
                    
                    基本语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    数据类型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="general.html">
            
                <a href="general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="null-undefined-boolean.html">
            
                <a href="null-undefined-boolean.html">
            
                    
                    null,undefined和布尔值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="number.html">
            
                <a href="number.html">
            
                    
                    数值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="string.html">
            
                <a href="string.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="object.html">
            
                <a href="object.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.6" data-path="function.html">
            
                <a href="function.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="array.html">
            
                <a href="array.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../operators/">
            
                <a href="../operators/">
            
                    
                    运算符
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../operators/arithmetic.html">
            
                <a href="../operators/arithmetic.html">
            
                    
                    算术运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../operators/comparison.html">
            
                <a href="../operators/comparison.html">
            
                    
                    比较运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../operators/boolean.html">
            
                <a href="../operators/boolean.html">
            
                    
                    布尔运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../operators/bit.html">
            
                <a href="../operators/bit.html">
            
                    
                    二进制位运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../operators/priority.html">
            
                <a href="../operators/priority.html">
            
                    
                    其他运算符，运算顺序
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../features/">
            
                <a href="../features/">
            
                    
                    语法专题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../features/conversion.html">
            
                <a href="../features/conversion.html">
            
                    
                    数据类型的转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../features/error.html">
            
                <a href="../features/error.html">
            
                    
                    错误处理机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../features/style.html">
            
                <a href="../features/style.html">
            
                    
                    编程风格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../features/console.html">
            
                <a href="../features/console.html">
            
                    
                    console 对象与控制台
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../stdlib/">
            
                <a href="../stdlib/">
            
                    
                    标准库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../stdlib/object.html">
            
                <a href="../stdlib/object.html">
            
                    
                    Object 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../stdlib/attributes.html">
            
                <a href="../stdlib/attributes.html">
            
                    
                    属性描述对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../stdlib/array.html">
            
                <a href="../stdlib/array.html">
            
                    
                    Array 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../stdlib/wrapper.html">
            
                <a href="../stdlib/wrapper.html">
            
                    
                    包装对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../stdlib/boolean.html">
            
                <a href="../stdlib/boolean.html">
            
                    
                    Boolean 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../stdlib/number.html">
            
                <a href="../stdlib/number.html">
            
                    
                    Number 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../stdlib/string.html">
            
                <a href="../stdlib/string.html">
            
                    
                    String 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../stdlib/math.html">
            
                <a href="../stdlib/math.html">
            
                    
                    Math 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../stdlib/date.html">
            
                <a href="../stdlib/date.html">
            
                    
                    Date 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../stdlib/regexp.html">
            
                <a href="../stdlib/regexp.html">
            
                    
                    RegExp 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../stdlib/json.html">
            
                <a href="../stdlib/json.html">
            
                    
                    JSON 对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../oop/">
            
                <a href="../oop/">
            
                    
                    面向对象编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../oop/new.html">
            
                <a href="../oop/new.html">
            
                    
                    实例对象与 New 命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../oop/this.html">
            
                <a href="../oop/this.html">
            
                    
                    this 关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../oop/prototype.html">
            
                <a href="../oop/prototype.html">
            
                    
                    对象的继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../oop/object.html">
            
                <a href="../oop/object.html">
            
                    
                    Object 对象的相关方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../oop/strict.html">
            
                <a href="../oop/strict.html">
            
                    
                    严格模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../async/">
            
                <a href="../async/">
            
                    
                    异步操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../async/general.html">
            
                <a href="../async/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../async/timer.html">
            
                <a href="../async/timer.html">
            
                    
                    定时器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../async/promise.html">
            
                <a href="../async/promise.html">
            
                    
                    Promise 对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../dom/">
            
                <a href="../dom/">
            
                    
                    DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../dom/general.html">
            
                <a href="../dom/general.html">
            
                    
                    概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../dom/node.html">
            
                <a href="../dom/node.html">
            
                    
                    Node 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../dom/nodelist.html">
            
                <a href="../dom/nodelist.html">
            
                    
                    NodeList 接口，HTMLCollection 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../dom/parentnode.html">
            
                <a href="../dom/parentnode.html">
            
                    
                    ParentNode 接口，ChildNode 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../dom/document.html">
            
                <a href="../dom/document.html">
            
                    
                    Document 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../dom/element.html">
            
                <a href="../dom/element.html">
            
                    
                    Element 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../dom/attributes.html">
            
                <a href="../dom/attributes.html">
            
                    
                    属性的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" data-path="../dom/text.html">
            
                <a href="../dom/text.html">
            
                    
                    Text 节点和 DocumentFragment 节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.9" data-path="../dom/css.html">
            
                <a href="../dom/css.html">
            
                    
                    CSS 操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.10" data-path="../dom/mutationobserver.html">
            
                <a href="../dom/mutationobserver.html">
            
                    
                    Mutation Observer API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../events/">
            
                <a href="../events/">
            
                    
                    事件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../events/eventtarget.html">
            
                <a href="../events/eventtarget.html">
            
                    
                    EventTarget 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../events/model.html">
            
                <a href="../events/model.html">
            
                    
                    事件模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../events/event.html">
            
                <a href="../events/event.html">
            
                    
                    Event 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../events/mouse.html">
            
                <a href="../events/mouse.html">
            
                    
                    鼠标事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../events/keyboard.html">
            
                <a href="../events/keyboard.html">
            
                    
                    键盘事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../events/progress.html">
            
                <a href="../events/progress.html">
            
                    
                    进度事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../events/form.html">
            
                <a href="../events/form.html">
            
                    
                    表单事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../events/touch.html">
            
                <a href="../events/touch.html">
            
                    
                    触摸事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../events/drag.html">
            
                <a href="../events/drag.html">
            
                    
                    拖拉事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.10" data-path="../events/common.html">
            
                <a href="../events/common.html">
            
                    
                    其他常见事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.11" data-path="../events/globaleventhandlers.html">
            
                <a href="../events/globaleventhandlers.html">
            
                    
                    GlobalEventHandlers 接口
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../bom/">
            
                <a href="../bom/">
            
                    
                    浏览器模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../bom/engine.html">
            
                <a href="../bom/engine.html">
            
                    
                    浏览器模型概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../bom/window.html">
            
                <a href="../bom/window.html">
            
                    
                    window 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../bom/navigator.html">
            
                <a href="../bom/navigator.html">
            
                    
                    Navigatror 对象，Screen 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../bom/cookie.html">
            
                <a href="../bom/cookie.html">
            
                    
                    Cookie
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../bom/xmlhttprequest.html">
            
                <a href="../bom/xmlhttprequest.html">
            
                    
                    XMLHttpRequest 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../bom/same-origin.html">
            
                <a href="../bom/same-origin.html">
            
                    
                    同源限制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../bom/cors.html">
            
                <a href="../bom/cors.html">
            
                    
                    CORS 通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../bom/storage.html">
            
                <a href="../bom/storage.html">
            
                    
                    Storage 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../bom/history.html">
            
                <a href="../bom/history.html">
            
                    
                    History 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../bom/location.html">
            
                <a href="../bom/location.html">
            
                    
                    Location对象，URL对象，URLSearchParams 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../bom/arraybuffer.html">
            
                <a href="../bom/arraybuffer.html">
            
                    
                    ArrayBuffer 对象，Blob对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../bom/file.html">
            
                <a href="../bom/file.html">
            
                    
                    File 对象，FileList 对象，FileReader 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../bom/form.html">
            
                <a href="../bom/form.html">
            
                    
                    表单，FormData 对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../bom/indexeddb.html">
            
                <a href="../bom/indexeddb.html">
            
                    
                    IndexedDB API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../bom/webworker.html">
            
                <a href="../bom/webworker.html">
            
                    
                    web worker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../elements/">
            
                <a href="../elements/">
            
                    
                    附录:网页元素接口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../elements/a.html">
            
                <a href="../elements/a.html">
            
                    
                    a超链接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../elements/image.html">
            
                <a href="../elements/image.html">
            
                    
                    image图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../elements/form.html">
            
                <a href="../elements/form.html">
            
                    
                    form表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../elements/input.html">
            
                <a href="../elements/input.html">
            
                    
                    input文本框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../elements/button.html">
            
                <a href="../elements/button.html">
            
                    
                    button按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../elements/option.html">
            
                <a href="../elements/option.html">
            
                    
                    option选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../elements/video.html">
            
                <a href="../elements/video.html">
            
                    
                    video,audio音视频
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="_blank" rel="nofollow" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >函数</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x51FD;&#x6570;">&#x51FD;&#x6570;</h1>
<p>&#x51FD;&#x6570;&#x662F;&#x4E00;&#x6BB5;&#x53EF;&#x4EE5;&#x53CD;&#x590D;&#x8C03;&#x7528;&#x7684;&#x4EE3;&#x7801;&#x5757;&#x3002;&#x51FD;&#x6570;&#x8FD8;&#x80FD;&#x63A5;&#x53D7;&#x8F93;&#x5165;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x53C2;&#x6570;&#x4F1A;&#x8FD4;&#x56DE;&#x4E0D;&#x540C;&#x7684;&#x503C;&#x3002;</p>
<h2 id="&#x6982;&#x8FF0;">&#x6982;&#x8FF0;</h2>
<h3 id="&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;">&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;</h3>
<p>JavaScript &#x6709;&#x4E09;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<p><strong>&#xFF08;1&#xFF09;function &#x547D;&#x4EE4;</strong></p>
<p><code>function</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x7684;&#x4EE3;&#x7801;&#x533A;&#x5757;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x3002;<code>function</code>&#x547D;&#x4EE4;&#x540E;&#x9762;&#x662F;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x51FD;&#x6570;&#x540D;&#x540E;&#x9762;&#x662F;&#x4E00;&#x5BF9;&#x5706;&#x62EC;&#x53F7;&#xFF0C;&#x91CC;&#x9762;&#x662F;&#x4F20;&#x5165;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;&#x51FD;&#x6570;&#x4F53;&#x653E;&#x5728;&#x5927;&#x62EC;&#x53F7;&#x91CC;&#x9762;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">print</span>(<span class="hljs-params">s</span>) </span>{
  <span class="hljs-built_in">console</span>.log(s);
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x547D;&#x540D;&#x4E86;&#x4E00;&#x4E2A;<code>print</code>&#x51FD;&#x6570;&#xFF0C;&#x4EE5;&#x540E;&#x4F7F;&#x7528;<code>print()</code>&#x8FD9;&#x79CD;&#x5F62;&#x5F0F;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x76F8;&#x5E94;&#x7684;&#x4EE3;&#x7801;&#x3002;&#x8FD9;&#x53EB;&#x505A;&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;&#xFF08;Function Declaration&#xFF09;&#x3002;</p>
<p><strong>&#xFF08;2&#xFF09;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;</strong></p>
<p>&#x9664;&#x4E86;&#x7528;<code>function</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x51FD;&#x6570;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#x7684;&#x5199;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> print = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">s</span>) </span>{
  <span class="hljs-built_in">console</span>.log(s);
};
</code></pre>
<p>&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x5C06;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;&#x3002;&#x8FD9;&#x65F6;&#xFF0C;&#x8FD9;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x53C8;&#x79F0;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;Function Expression&#xFF09;&#xFF0C;&#x56E0;&#x4E3A;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x7684;&#x7B49;&#x53F7;&#x53F3;&#x4FA7;&#x53EA;&#x80FD;&#x653E;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<p>&#x91C7;&#x7528;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x65F6;&#xFF0C;<code>function</code>&#x547D;&#x4EE4;&#x540E;&#x9762;&#x4E0D;&#x5E26;&#x6709;&#x51FD;&#x6570;&#x540D;&#x3002;&#x5982;&#x679C;&#x52A0;&#x4E0A;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x8BE5;&#x51FD;&#x6570;&#x540D;&#x53EA;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x6709;&#x6548;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5916;&#x90E8;&#x65E0;&#x6548;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> print = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">x</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> x);
};

x
<span class="hljs-comment">// ReferenceError: x is not defined</span>

print()
<span class="hljs-comment">// function</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5728;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#xFF0C;&#x52A0;&#x5165;&#x4E86;&#x51FD;&#x6570;&#x540D;<code>x</code>&#x3002;&#x8FD9;&#x4E2A;<code>x</code>&#x53EA;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x53EF;&#x7528;&#xFF0C;&#x6307;&#x4EE3;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x672C;&#x8EAB;&#xFF0C;&#x5176;&#x4ED6;&#x5730;&#x65B9;&#x90FD;&#x4E0D;&#x53EF;&#x7528;&#x3002;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x7684;&#x7528;&#x5904;&#x6709;&#x4E24;&#x4E2A;&#xFF0C;&#x4E00;&#x662F;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x8C03;&#x7528;&#x81EA;&#x8EAB;&#xFF0C;&#x4E8C;&#x662F;&#x65B9;&#x4FBF;&#x9664;&#x9519;&#xFF08;&#x9664;&#x9519;&#x5DE5;&#x5177;&#x663E;&#x793A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x6808;&#x65F6;&#xFF0C;&#x5C06;&#x663E;&#x793A;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x800C;&#x4E0D;&#x518D;&#x663E;&#x793A;&#x8FD9;&#x91CC;&#x662F;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#xFF09;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x5F62;&#x5F0F;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x4E5F;&#x975E;&#x5E38;&#x5E38;&#x89C1;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{};
</code></pre>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x51FD;&#x6570;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x9700;&#x8981;&#x5728;&#x8BED;&#x53E5;&#x7684;&#x7ED3;&#x5C3E;&#x52A0;&#x4E0A;&#x5206;&#x53F7;&#xFF0C;&#x8868;&#x793A;&#x8BED;&#x53E5;&#x7ED3;&#x675F;&#x3002;&#x800C;&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;&#x5728;&#x7ED3;&#x5C3E;&#x7684;&#x5927;&#x62EC;&#x53F7;&#x540E;&#x9762;&#x4E0D;&#x7528;&#x52A0;&#x5206;&#x53F7;&#x3002;&#x603B;&#x7684;&#x6765;&#x8BF4;&#xFF0C;&#x8FD9;&#x4E24;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5DEE;&#x522B;&#x5F88;&#x7EC6;&#x5FAE;&#xFF0C;&#x53EF;&#x4EE5;&#x8FD1;&#x4F3C;&#x8BA4;&#x4E3A;&#x662F;&#x7B49;&#x4EF7;&#x7684;&#x3002;</p>
<p><strong>&#xFF08;3&#xFF09;Function &#x6784;&#x9020;&#x51FD;&#x6570;</strong></p>
<p>&#x7B2C;&#x4E09;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x662F;<code>Function</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> add = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(
  <span class="hljs-string">&apos;x&apos;</span>,
  <span class="hljs-string">&apos;y&apos;</span>,
  <span class="hljs-string">&apos;return x + y&apos;</span>
);

<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">return</span> x + y;
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Function</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x63A5;&#x53D7;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x9664;&#x4E86;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;<code>add</code>&#x51FD;&#x6570;&#x7684;&#x201C;&#x51FD;&#x6570;&#x4F53;&#x201D;&#xFF0C;&#x5176;&#x4ED6;&#x53C2;&#x6570;&#x90FD;&#x662F;<code>add</code>&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x4F20;&#x9012;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x53C2;&#x6570;&#x7ED9;<code>Function</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x53EA;&#x6709;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x5F53;&#x505A;&#x51FD;&#x6570;&#x4F53;&#xFF0C;&#x5982;&#x679C;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8BE5;&#x53C2;&#x6570;&#x5C31;&#x662F;&#x51FD;&#x6570;&#x4F53;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> foo = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(
  <span class="hljs-string">&apos;return &quot;hello world&quot;;&apos;</span>
);

<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;hello world&apos;</span>;
}
</code></pre>
<p><code>Function</code>&#x6784;&#x9020;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x4E0D;&#x4F7F;&#x7528;<code>new</code>&#x547D;&#x4EE4;&#xFF0C;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x5B8C;&#x5168;&#x4E00;&#x6837;&#x3002;</p>
<p>&#x603B;&#x7684;&#x6765;&#x8BF4;&#xFF0C;&#x8FD9;&#x79CD;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x975E;&#x5E38;&#x4E0D;&#x76F4;&#x89C2;&#xFF0C;&#x51E0;&#x4E4E;&#x65E0;&#x4EBA;&#x4F7F;&#x7528;&#x3002;</p>
<h3 id="&#x51FD;&#x6570;&#x7684;&#x91CD;&#x590D;&#x58F0;&#x660E;">&#x51FD;&#x6570;&#x7684;&#x91CD;&#x590D;&#x58F0;&#x660E;</h3>
<p>&#x5982;&#x679C;&#x540C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x88AB;&#x591A;&#x6B21;&#x58F0;&#x660E;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x58F0;&#x660E;&#x5C31;&#x4F1A;&#x8986;&#x76D6;&#x524D;&#x9762;&#x7684;&#x58F0;&#x660E;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
}
f() <span class="hljs-comment">// 2</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
}
f() <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x540E;&#x4E00;&#x6B21;&#x7684;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x8986;&#x76D6;&#x4E86;&#x524D;&#x9762;&#x4E00;&#x6B21;&#x3002;&#x800C;&#x4E14;&#xFF0C;&#x7531;&#x4E8E;&#x51FD;&#x6570;&#x540D;&#x7684;&#x63D0;&#x5347;&#xFF08;&#x53C2;&#x89C1;&#x4E0B;&#x6587;&#xFF09;&#xFF0C;&#x524D;&#x4E00;&#x6B21;&#x58F0;&#x660E;&#x5728;&#x4EFB;&#x4F55;&#x65F6;&#x5019;&#x90FD;&#x662F;&#x65E0;&#x6548;&#x7684;&#xFF0C;&#x8FD9;&#x4E00;&#x70B9;&#x8981;&#x7279;&#x522B;&#x6CE8;&#x610F;&#x3002;</p>
<h3 id="&#x5706;&#x62EC;&#x53F7;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;return-&#x8BED;&#x53E5;&#x548C;&#x9012;&#x5F52;">&#x5706;&#x62EC;&#x53F7;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;return &#x8BED;&#x53E5;&#x548C;&#x9012;&#x5F52;</h3>
<p>&#x8C03;&#x7528;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x8981;&#x4F7F;&#x7528;&#x5706;&#x62EC;&#x53F7;&#x8FD0;&#x7B97;&#x7B26;&#x3002;&#x5706;&#x62EC;&#x53F7;&#x4E4B;&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x52A0;&#x5165;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">return</span> x + y;
}

add(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;&#x540D;&#x540E;&#x9762;&#x7D27;&#x8DDF;&#x4E00;&#x5BF9;&#x5706;&#x62EC;&#x53F7;&#xFF0C;&#x5C31;&#x4F1A;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x7684;<code>return</code>&#x8BED;&#x53E5;&#xFF0C;&#x8868;&#x793A;&#x8FD4;&#x56DE;&#x3002;JavaScript &#x5F15;&#x64CE;&#x9047;&#x5230;<code>return</code>&#x8BED;&#x53E5;&#xFF0C;&#x5C31;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;<code>return</code>&#x540E;&#x9762;&#x7684;&#x90A3;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x503C;&#xFF0C;&#x540E;&#x9762;&#x5373;&#x4F7F;&#x8FD8;&#x6709;&#x8BED;&#x53E5;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x5F97;&#x5230;&#x6267;&#x884C;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;<code>return</code>&#x8BED;&#x53E5;&#x6240;&#x5E26;&#x7684;&#x90A3;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x5C31;&#x662F;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x3002;<code>return</code>&#x8BED;&#x53E5;&#x4E0D;&#x662F;&#x5FC5;&#x9700;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x7684;&#x8BDD;&#xFF0C;&#x8BE5;&#x51FD;&#x6570;&#x5C31;&#x4E0D;&#x8FD4;&#x56DE;&#x4EFB;&#x4F55;&#x503C;&#xFF0C;&#x6216;&#x8005;&#x8BF4;&#x8FD4;&#x56DE;<code>undefined</code>&#x3002;</p>
<p>&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x81EA;&#x8EAB;&#xFF0C;&#x8FD9;&#x5C31;&#x662F;&#x9012;&#x5F52;&#xFF08;recursion&#xFF09;&#x3002;&#x4E0B;&#x9762;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x9012;&#x5F52;&#xFF0C;&#x8BA1;&#x7B97;&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fib</span>(<span class="hljs-params">num</span>) </span>{
  <span class="hljs-keyword">if</span> (num === <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
  <span class="hljs-keyword">if</span> (num === <span class="hljs-number">1</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
  <span class="hljs-keyword">return</span> fib(num - <span class="hljs-number">2</span>) + fib(num - <span class="hljs-number">1</span>);
}

fib(<span class="hljs-number">6</span>) <span class="hljs-comment">// 8</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>fib</code>&#x51FD;&#x6570;&#x5185;&#x90E8;&#x53C8;&#x8C03;&#x7528;&#x4E86;<code>fib</code>&#xFF0C;&#x8BA1;&#x7B97;&#x5F97;&#x5230;&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;&#x7684;&#x7B2C;6&#x4E2A;&#x5143;&#x7D20;&#x662F;8&#x3002;</p>
<h3 id="&#x7B2C;&#x4E00;&#x7B49;&#x516C;&#x6C11;">&#x7B2C;&#x4E00;&#x7B49;&#x516C;&#x6C11;</h3>
<p>JavaScript &#x8BED;&#x8A00;&#x5C06;&#x51FD;&#x6570;&#x770B;&#x4F5C;&#x4E00;&#x79CD;&#x503C;&#xFF0C;&#x4E0E;&#x5176;&#x5B83;&#x503C;&#xFF08;&#x6570;&#x503C;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x5E03;&#x5C14;&#x503C;&#x7B49;&#x7B49;&#xFF09;&#x5730;&#x4F4D;&#x76F8;&#x540C;&#x3002;&#x51E1;&#x662F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x503C;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x5C31;&#x80FD;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x3002;&#x6BD4;&#x5982;&#xFF0C;&#x53EF;&#x4EE5;&#x628A;&#x51FD;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;&#x548C;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5F53;&#x4F5C;&#x53C2;&#x6570;&#x4F20;&#x5165;&#x5176;&#x4ED6;&#x51FD;&#x6570;&#xFF0C;&#x6216;&#x8005;&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x7684;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x3002;&#x51FD;&#x6570;&#x53EA;&#x662F;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x6267;&#x884C;&#x7684;&#x503C;&#xFF0C;&#x6B64;&#x5916;&#x5E76;&#x65E0;&#x7279;&#x6B8A;&#x4E4B;&#x5904;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x51FD;&#x6570;&#x4E0E;&#x5176;&#x4ED6;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5730;&#x4F4D;&#x5E73;&#x7B49;&#xFF0C;&#x6240;&#x4EE5;&#x5728; JavaScript &#x8BED;&#x8A00;&#x4E2D;&#x53C8;&#x79F0;&#x51FD;&#x6570;&#x4E3A;&#x7B2C;&#x4E00;&#x7B49;&#x516C;&#x6C11;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">x, y</span>) </span>{
  <span class="hljs-keyword">return</span> x + y;
}

<span class="hljs-comment">// &#x5C06;&#x51FD;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;</span>
<span class="hljs-keyword">var</span> operator = add;

<span class="hljs-comment">// &#x5C06;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">a</span>(<span class="hljs-params">op</span>)</span>{
  <span class="hljs-keyword">return</span> op;
}
a(add)(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>)
<span class="hljs-comment">// 2</span>
</code></pre>
<h3 id="&#x51FD;&#x6570;&#x540D;&#x7684;&#x63D0;&#x5347;">&#x51FD;&#x6570;&#x540D;&#x7684;&#x63D0;&#x5347;</h3>
<p>JavaScript &#x5F15;&#x64CE;&#x5C06;&#x51FD;&#x6570;&#x540D;&#x89C6;&#x540C;&#x53D8;&#x91CF;&#x540D;&#xFF0C;&#x6240;&#x4EE5;&#x91C7;&#x7528;<code>function</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x6574;&#x4E2A;&#x51FD;&#x6570;&#x4F1A;&#x50CF;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#x4E00;&#x6837;&#xFF0C;&#x88AB;&#x63D0;&#x5347;&#x5230;&#x4EE3;&#x7801;&#x5934;&#x90E8;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript">f();

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p>&#x8868;&#x9762;&#x4E0A;&#xFF0C;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x597D;&#x50CF;&#x5728;&#x58F0;&#x660E;&#x4E4B;&#x524D;&#x5C31;&#x8C03;&#x7528;&#x4E86;&#x51FD;&#x6570;<code>f</code>&#x3002;&#x4F46;&#x662F;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x7531;&#x4E8E;&#x201C;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#x201D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x88AB;&#x63D0;&#x5347;&#x5230;&#x4E86;&#x4EE3;&#x7801;&#x5934;&#x90E8;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5728;&#x8C03;&#x7528;&#x4E4B;&#x524D;&#x5DF2;&#x7ECF;&#x58F0;&#x660E;&#x4E86;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x91C7;&#x7528;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#xFF0C;JavaScript &#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript">f();
<span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{};
<span class="hljs-comment">// TypeError: undefined is not a function</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x7B49;&#x540C;&#x4E8E;&#x4E0B;&#x9762;&#x7684;&#x5F62;&#x5F0F;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f;
f();
f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7B2C;&#x4E8C;&#x884C;&#xFF0C;&#x8C03;&#x7528;<code>f</code>&#x7684;&#x65F6;&#x5019;&#xFF0C;<code>f</code>&#x53EA;&#x662F;&#x88AB;&#x58F0;&#x660E;&#x4E86;&#xFF0C;&#x8FD8;&#x6CA1;&#x6709;&#x88AB;&#x8D4B;&#x503C;&#xFF0C;&#x7B49;&#x4E8E;<code>undefined</code>&#xFF0C;&#x6240;&#x4EE5;&#x4F1A;&#x62A5;&#x9519;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5982;&#x679C;&#x540C;&#x65F6;&#x91C7;&#x7528;<code>function</code>&#x547D;&#x4EE4;&#x548C;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x58F0;&#x660E;&#x540C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x6700;&#x540E;&#x603B;&#x662F;&#x91C7;&#x7528;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x7684;&#x5B9A;&#x4E49;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;1&apos;</span>);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;2&apos;</span>);
}

f() <span class="hljs-comment">// 1</span>
</code></pre>
<h2 id="&#x51FD;&#x6570;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;">&#x51FD;&#x6570;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;</h2>
<h3 id="name-&#x5C5E;&#x6027;">name &#x5C5E;&#x6027;</h3>
<p>&#x51FD;&#x6570;&#x7684;<code>name</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;&#x51FD;&#x6570;&#x7684;&#x540D;&#x5B57;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params"></span>) </span>{}
f1.name <span class="hljs-comment">// &quot;f1&quot;</span>
</code></pre>
<p>&#x5982;&#x679C;&#x662F;&#x901A;&#x8FC7;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#x5B9A;&#x4E49;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;<code>name</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;&#x53D8;&#x91CF;&#x540D;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f2 = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};
f2.name <span class="hljs-comment">// &quot;f2&quot;</span>
</code></pre>
<p>&#x4F46;&#x662F;&#xFF0C;&#x4E0A;&#x9762;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x53EA;&#x6709;&#x5728;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x533F;&#x540D;&#x51FD;&#x6570;&#x65F6;&#x624D;&#x662F;&#x5982;&#x6B64;&#x3002;&#x5982;&#x679C;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x5177;&#x540D;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;<code>name</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;<code>function</code>&#x5173;&#x952E;&#x5B57;&#x4E4B;&#x540E;&#x7684;&#x90A3;&#x4E2A;&#x51FD;&#x6570;&#x540D;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f3 = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">myName</span>(<span class="hljs-params"></span>) </span>{};
f3.name <span class="hljs-comment">// &apos;myName&apos;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>f3.name</code>&#x8FD4;&#x56DE;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x540D;&#x5B57;&#x3002;&#x6CE8;&#x610F;&#xFF0C;&#x771F;&#x6B63;&#x7684;&#x51FD;&#x6570;&#x540D;&#x8FD8;&#x662F;<code>f3</code>&#xFF0C;&#x800C;<code>myName</code>&#x8FD9;&#x4E2A;&#x540D;&#x5B57;&#x53EA;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x53EF;&#x7528;&#x3002;</p>
<p><code>name</code>&#x5C5E;&#x6027;&#x7684;&#x4E00;&#x4E2A;&#x7528;&#x5904;&#xFF0C;&#x5C31;&#x662F;&#x83B7;&#x53D6;&#x53C2;&#x6570;&#x51FD;&#x6570;&#x7684;&#x540D;&#x5B57;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> myFunc = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params">f</span>) </span>{
  <span class="hljs-built_in">console</span>.log(f.name);
}

test(myFunc) <span class="hljs-comment">// myFunc</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>test</code>&#x5185;&#x90E8;&#x901A;&#x8FC7;<code>name</code>&#x5C5E;&#x6027;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x77E5;&#x9053;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x662F;&#x4EC0;&#x4E48;&#x51FD;&#x6570;&#x3002;</p>
<h3 id="length-&#x5C5E;&#x6027;">length &#x5C5E;&#x6027;</h3>
<p>&#x51FD;&#x6570;&#x7684;<code>length</code>&#x5C5E;&#x6027;&#x8FD4;&#x56DE;&#x51FD;&#x6570;&#x9884;&#x671F;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#xFF0C;&#x5373;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x4E4B;&#x4E2D;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, b</span>) </span>{}
f.length <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5B9A;&#x4E49;&#x4E86;&#x7A7A;&#x51FD;&#x6570;<code>f</code>&#xFF0C;&#x5B83;&#x7684;<code>length</code>&#x5C5E;&#x6027;&#x5C31;&#x662F;&#x5B9A;&#x4E49;&#x65F6;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x3002;&#x4E0D;&#x7BA1;&#x8C03;&#x7528;&#x65F6;&#x8F93;&#x5165;&#x4E86;&#x591A;&#x5C11;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;<code>length</code>&#x5C5E;&#x6027;&#x59CB;&#x7EC8;&#x7B49;&#x4E8E;2&#x3002;</p>
<p><code>length</code>&#x5C5E;&#x6027;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x5224;&#x65AD;&#x5B9A;&#x4E49;&#x65F6;&#x548C;&#x8C03;&#x7528;&#x65F6;&#x53C2;&#x6570;&#x7684;&#x5DEE;&#x5F02;&#xFF0C;&#x4EE5;&#x4FBF;&#x5B9E;&#x73B0;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7F16;&#x7A0B;&#x7684;&#x201C;&#x65B9;&#x6CD5;&#x91CD;&#x8F7D;&#x201D;&#xFF08;overload&#xFF09;&#x3002;</p>
<h3 id="tostring">toString()</h3>
<p>&#x51FD;&#x6570;&#x7684;<code>toString</code>&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5185;&#x5BB9;&#x662F;&#x51FD;&#x6570;&#x7684;&#x6E90;&#x7801;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  a();
  b();
  c();
}

f.toString()
<span class="hljs-comment">// function f() {</span>
<span class="hljs-comment">//  a();</span>
<span class="hljs-comment">//  b();</span>
<span class="hljs-comment">//  c();</span>
<span class="hljs-comment">// }</span>
</code></pre>
<p>&#x5BF9;&#x4E8E;&#x90A3;&#x4E9B;&#x539F;&#x751F;&#x7684;&#x51FD;&#x6570;&#xFF0C;<code>toString()</code>&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;<code>function (){[native code]}</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">Math</span>.sqrt.toString()
<span class="hljs-comment">// &quot;function sqrt() { [native code] }&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>Math.sqrt</code>&#x662F; JavaScript &#x5F15;&#x64CE;&#x63D0;&#x4F9B;&#x7684;&#x539F;&#x751F;&#x51FD;&#x6570;&#xFF0C;<code>toString()</code>&#x65B9;&#x6CD5;&#x5C31;&#x8FD4;&#x56DE;&#x539F;&#x751F;&#x4EE3;&#x7801;&#x7684;&#x63D0;&#x793A;&#x3002;</p>
<p>&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x6CE8;&#x91CA;&#x4E5F;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{<span class="hljs-comment">/*
  &#x8FD9;&#x662F;&#x4E00;&#x4E2A;
  &#x591A;&#x884C;&#x6CE8;&#x91CA;
*/</span>}

f.toString()
<span class="hljs-comment">// &quot;function f(){/*</span>
<span class="hljs-comment">//   &#x8FD9;&#x662F;&#x4E00;&#x4E2A;</span>
<span class="hljs-comment">//   &#x591A;&#x884C;&#x6CE8;&#x91CA;</span>
<span class="hljs-comment">// */}&quot;</span>
</code></pre>
<p>&#x5229;&#x7528;&#x8FD9;&#x4E00;&#x70B9;&#xFF0C;&#x53EF;&#x4EE5;&#x53D8;&#x76F8;&#x5B9E;&#x73B0;&#x591A;&#x884C;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> multiline = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">fn</span>) </span>{
  <span class="hljs-keyword">var</span> arr = fn.toString().split(<span class="hljs-string">&apos;\n&apos;</span>);
  <span class="hljs-keyword">return</span> arr.slice(<span class="hljs-number">1</span>, arr.length - <span class="hljs-number">1</span>).join(<span class="hljs-string">&apos;\n&apos;</span>);
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{<span class="hljs-comment">/*
  &#x8FD9;&#x662F;&#x4E00;&#x4E2A;
  &#x591A;&#x884C;&#x6CE8;&#x91CA;
*/</span>}

multiline(f);
<span class="hljs-comment">// &quot; &#x8FD9;&#x662F;&#x4E00;&#x4E2A;</span>
<span class="hljs-comment">//   &#x591A;&#x884C;&#x6CE8;&#x91CA;&quot;</span>
</code></pre>
<h2 id="&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;">&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;</h2>
<h3 id="&#x5B9A;&#x4E49;">&#x5B9A;&#x4E49;</h3>
<p>&#x4F5C;&#x7528;&#x57DF;&#xFF08;scope&#xFF09;&#x6307;&#x7684;&#x662F;&#x53D8;&#x91CF;&#x5B58;&#x5728;&#x7684;&#x8303;&#x56F4;&#x3002;&#x5728; ES5 &#x7684;&#x89C4;&#x8303;&#x4E2D;&#xFF0C;JavaScript &#x53EA;&#x6709;&#x4E24;&#x79CD;&#x4F5C;&#x7528;&#x57DF;&#xFF1A;&#x4E00;&#x79CD;&#x662F;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x53D8;&#x91CF;&#x5728;&#x6574;&#x4E2A;&#x7A0B;&#x5E8F;&#x4E2D;&#x4E00;&#x76F4;&#x5B58;&#x5728;&#xFF0C;&#x6240;&#x6709;&#x5730;&#x65B9;&#x90FD;&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#xFF1B;&#x53E6;&#x4E00;&#x79CD;&#x662F;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x53D8;&#x91CF;&#x53EA;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B58;&#x5728;&#x3002;ES6 &#x53C8;&#x65B0;&#x589E;&#x4E86;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x672C;&#x6559;&#x7A0B;&#x4E0D;&#x6D89;&#x53CA;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x9876;&#x5C42;&#x51FD;&#x6570;&#x6765;&#x8BF4;&#xFF0C;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x5C31;&#x662F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF08;global variable&#xFF09;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x8BFB;&#x53D6;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> v = <span class="hljs-number">1</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(v);
}

f()
<span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x8868;&#x660E;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x5185;&#x90E8;&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#x5168;&#x5C40;&#x53D8;&#x91CF;<code>v</code>&#x3002;</p>
<p>&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5916;&#x90E8;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#xFF0C;&#x79F0;&#x4E3A;&#x201C;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x201D;&#xFF08;local variable&#xFF09;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-keyword">var</span> v = <span class="hljs-number">1</span>;
}

v <span class="hljs-comment">// ReferenceError: v is not defined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53D8;&#x91CF;<code>v</code>&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#xFF0C;&#x6240;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x51FD;&#x6570;&#x4E4B;&#x5916;&#x5C31;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#x3002;</p>
<p>&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x4F1A;&#x5728;&#x8BE5;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x8986;&#x76D6;&#x540C;&#x540D;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> v = <span class="hljs-number">1</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-keyword">var</span> v = <span class="hljs-number">2</span>;
  <span class="hljs-built_in">console</span>.log(v);
}

f() <span class="hljs-comment">// 2</span>
v <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53D8;&#x91CF;<code>v</code>&#x540C;&#x65F6;&#x5728;&#x51FD;&#x6570;&#x7684;&#x5916;&#x90E8;&#x548C;&#x5185;&#x90E8;&#x6709;&#x5B9A;&#x4E49;&#x3002;&#x7ED3;&#x679C;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#xFF0C;&#x5C40;&#x90E8;&#x53D8;&#x91CF;<code>v</code>&#x8986;&#x76D6;&#x4E86;&#x5168;&#x5C40;&#x53D8;&#x91CF;<code>v</code>&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5BF9;&#x4E8E;<code>var</code>&#x547D;&#x4EE4;&#x6765;&#x8BF4;&#xFF0C;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x53EA;&#x80FD;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x58F0;&#x660E;&#xFF0C;&#x5728;&#x5176;&#x4ED6;&#x533A;&#x5757;&#x4E2D;&#x58F0;&#x660E;&#xFF0C;&#x4E00;&#x5F8B;&#x90FD;&#x662F;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
  <span class="hljs-keyword">var</span> x = <span class="hljs-number">5</span>;
}
<span class="hljs-built_in">console</span>.log(x);  <span class="hljs-comment">// 5</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53D8;&#x91CF;<code>x</code>&#x5728;&#x6761;&#x4EF6;&#x5224;&#x65AD;&#x533A;&#x5757;&#x4E4B;&#x4E2D;&#x58F0;&#x660E;&#xFF0C;&#x7ED3;&#x679C;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x533A;&#x5757;&#x4E4B;&#x5916;&#x8BFB;&#x53D6;&#x3002;</p>
<h3 id="&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#x63D0;&#x5347;">&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#x63D0;&#x5347;</h3>
<p>&#x4E0E;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x4E00;&#x6837;&#xFF0C;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x90E8;&#x4E5F;&#x4F1A;&#x4EA7;&#x751F;&#x201C;&#x53D8;&#x91CF;&#x63D0;&#x5347;&#x201D;&#x73B0;&#x8C61;&#x3002;<code>var</code>&#x547D;&#x4EE4;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x4E0D;&#x7BA1;&#x5728;&#x4EC0;&#x4E48;&#x4F4D;&#x7F6E;&#xFF0C;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#x90FD;&#x4F1A;&#x88AB;&#x63D0;&#x5347;&#x5230;&#x51FD;&#x6570;&#x4F53;&#x7684;&#x5934;&#x90E8;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">if</span> (x &gt; <span class="hljs-number">100</span>) {
    <span class="hljs-keyword">var</span> tmp = x - <span class="hljs-number">100</span>;
  }
}

<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">var</span> tmp;
  <span class="hljs-keyword">if</span> (x &gt; <span class="hljs-number">100</span>) {
    tmp = x - <span class="hljs-number">100</span>;
  };
}
</code></pre>
<h3 id="&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x7684;&#x4F5C;&#x7528;&#x57DF;">&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x7684;&#x4F5C;&#x7528;&#x57DF;</h3>
<p>&#x51FD;&#x6570;&#x672C;&#x8EAB;&#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x4E5F;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x3002;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4E0E;&#x53D8;&#x91CF;&#x4E00;&#x6837;&#xFF0C;&#x5C31;&#x662F;&#x5176;&#x58F0;&#x660E;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x4E0E;&#x5176;&#x8FD0;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x65E0;&#x5173;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> x = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> a = <span class="hljs-number">2</span>;
  x();
}

f() <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>x</code>&#x662F;&#x5728;&#x51FD;&#x6570;<code>f</code>&#x7684;&#x5916;&#x90E8;&#x58F0;&#x660E;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x7ED1;&#x5B9A;&#x5916;&#x5C42;&#xFF0C;&#x5185;&#x90E8;&#x53D8;&#x91CF;<code>a</code>&#x4E0D;&#x4F1A;&#x5230;&#x51FD;&#x6570;<code>f</code>&#x4F53;&#x5185;&#x53D6;&#x503C;&#xFF0C;&#x6240;&#x4EE5;&#x8F93;&#x51FA;<code>1</code>&#xFF0C;&#x800C;&#x4E0D;&#x662F;<code>2</code>&#x3002;</p>
<p>&#x603B;&#x4E4B;&#xFF0C;&#x51FD;&#x6570;&#x6267;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x662F;&#x5B9A;&#x4E49;&#x65F6;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x8C03;&#x7528;&#x65F6;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<p>&#x5F88;&#x5BB9;&#x6613;&#x72AF;&#x9519;&#x7684;&#x4E00;&#x70B9;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;<code>A</code>&#x8C03;&#x7528;&#x51FD;&#x6570;<code>B</code>&#xFF0C;&#x5374;&#x6CA1;&#x8003;&#x8651;&#x5230;&#x51FD;&#x6570;<code>B</code>&#x4E0D;&#x4F1A;&#x5F15;&#x7528;&#x51FD;&#x6570;<code>A</code>&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> x = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">y</span>(<span class="hljs-params">f</span>) </span>{
  <span class="hljs-keyword">var</span> a = <span class="hljs-number">2</span>;
  f();
}

y(x)
<span class="hljs-comment">// ReferenceError: a is not defined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5C06;&#x51FD;&#x6570;<code>x</code>&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;<code>y</code>&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x51FD;&#x6570;<code>x</code>&#x662F;&#x5728;&#x51FD;&#x6570;<code>y</code>&#x4F53;&#x5916;&#x58F0;&#x660E;&#x7684;&#xFF0C;&#x4F5C;&#x7528;&#x57DF;&#x7ED1;&#x5B9A;&#x5916;&#x5C42;&#xFF0C;&#x56E0;&#x6B64;&#x627E;&#x4E0D;&#x5230;&#x51FD;&#x6570;<code>y</code>&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;<code>a</code>&#xFF0C;&#x5BFC;&#x81F4;&#x62A5;&#x9519;&#x3002;</p>
<p>&#x540C;&#x6837;&#x7684;&#xFF0C;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x58F0;&#x660E;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x4F5C;&#x7528;&#x57DF;&#x7ED1;&#x5B9A;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> x = <span class="hljs-number">1</span>;
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(x);
  }
  <span class="hljs-keyword">return</span> bar;
}

<span class="hljs-keyword">var</span> x = <span class="hljs-number">2</span>;
<span class="hljs-keyword">var</span> f = foo();
f() <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>foo</code>&#x5185;&#x90E8;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A;&#x51FD;&#x6570;<code>bar</code>&#xFF0C;<code>bar</code>&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x7ED1;&#x5B9A;<code>foo</code>&#x3002;&#x5F53;&#x6211;&#x4EEC;&#x5728;<code>foo</code>&#x5916;&#x90E8;&#x53D6;&#x51FA;<code>bar</code>&#x6267;&#x884C;&#x65F6;&#xFF0C;&#x53D8;&#x91CF;<code>x</code>&#x6307;&#x5411;&#x7684;&#x662F;<code>foo</code>&#x5185;&#x90E8;&#x7684;<code>x</code>&#xFF0C;&#x800C;&#x4E0D;&#x662F;<code>foo</code>&#x5916;&#x90E8;&#x7684;<code>x</code>&#x3002;&#x6B63;&#x662F;&#x8FD9;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x6784;&#x6210;&#x4E86;&#x4E0B;&#x6587;&#x8981;&#x8BB2;&#x89E3;&#x7684;&#x201C;&#x95ED;&#x5305;&#x201D;&#x73B0;&#x8C61;&#x3002;</p>
<h2 id="&#x53C2;&#x6570;">&#x53C2;&#x6570;</h2>
<h3 id="&#x6982;&#x8FF0;">&#x6982;&#x8FF0;</h3>
<p>&#x51FD;&#x6570;&#x8FD0;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6709;&#x65F6;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x5916;&#x90E8;&#x6570;&#x636E;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x5916;&#x90E8;&#x6570;&#x636E;&#x4F1A;&#x5F97;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x7ED3;&#x679C;&#xFF0C;&#x8FD9;&#x79CD;&#x5916;&#x90E8;&#x6570;&#x636E;&#x5C31;&#x53EB;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">square</span>(<span class="hljs-params">x</span>) </span>{
  <span class="hljs-keyword">return</span> x * x;
}

square(<span class="hljs-number">2</span>) <span class="hljs-comment">// 4</span>
square(<span class="hljs-number">3</span>) <span class="hljs-comment">// 9</span>
</code></pre>
<p>&#x4E0A;&#x5F0F;&#x7684;<code>x</code>&#x5C31;&#x662F;<code>square</code>&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;&#x6BCF;&#x6B21;&#x8FD0;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x8FD9;&#x4E2A;&#x503C;&#xFF0C;&#x5426;&#x5219;&#x5F97;&#x4E0D;&#x5230;&#x7ED3;&#x679C;&#x3002;</p>
<h3 id="&#x53C2;&#x6570;&#x7684;&#x7701;&#x7565;">&#x53C2;&#x6570;&#x7684;&#x7701;&#x7565;</h3>
<p>&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4E0D;&#x662F;&#x5FC5;&#x9700;&#x7684;&#xFF0C;JavaScript &#x5141;&#x8BB8;&#x7701;&#x7565;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a;
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>) <span class="hljs-comment">// 1</span>
f(<span class="hljs-number">1</span>) <span class="hljs-comment">// 1</span>
f() <span class="hljs-comment">// undefined</span>

f.length <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x51FD;&#x6570;<code>f</code>&#x5B9A;&#x4E49;&#x4E86;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4F46;&#x662F;&#x8FD0;&#x884C;&#x65F6;&#x65E0;&#x8BBA;&#x63D0;&#x4F9B;&#x591A;&#x5C11;&#x4E2A;&#x53C2;&#x6570;&#xFF08;&#x6216;&#x8005;&#x4E0D;&#x63D0;&#x4F9B;&#x53C2;&#x6570;&#xFF09;&#xFF0C;JavaScript &#x90FD;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x3002;&#x7701;&#x7565;&#x7684;&#x53C2;&#x6570;&#x7684;&#x503C;&#x5C31;&#x53D8;&#x4E3A;<code>undefined</code>&#x3002;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x51FD;&#x6570;&#x7684;<code>length</code>&#x5C5E;&#x6027;&#x4E0E;&#x5B9E;&#x9645;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x65E0;&#x5173;&#xFF0C;&#x53EA;&#x53CD;&#x6620;&#x51FD;&#x6570;&#x9884;&#x671F;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x6CA1;&#x6709;&#x529E;&#x6CD5;&#x53EA;&#x7701;&#x7565;&#x9760;&#x524D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x800C;&#x4FDD;&#x7559;&#x9760;&#x540E;&#x7684;&#x53C2;&#x6570;&#x3002;&#x5982;&#x679C;&#x4E00;&#x5B9A;&#x8981;&#x7701;&#x7565;&#x9760;&#x524D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x53EA;&#x6709;&#x663E;&#x5F0F;&#x4F20;&#x5165;<code>undefined</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a;
}

f( , <span class="hljs-number">1</span>) <span class="hljs-comment">// SyntaxError: Unexpected token ,(&#x2026;)</span>
f(<span class="hljs-literal">undefined</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// undefined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x7701;&#x7565;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<h3 id="&#x4F20;&#x9012;&#x65B9;&#x5F0F;">&#x4F20;&#x9012;&#x65B9;&#x5F0F;</h3>
<p>&#x51FD;&#x6570;&#x53C2;&#x6570;&#x5982;&#x679C;&#x662F;&#x539F;&#x59CB;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF08;&#x6570;&#x503C;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x5E03;&#x5C14;&#x503C;&#xFF09;&#xFF0C;&#x4F20;&#x9012;&#x65B9;&#x5F0F;&#x662F;&#x4F20;&#x503C;&#x4F20;&#x9012;&#xFF08;passes by value&#xFF09;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x4FEE;&#x6539;&#x53C2;&#x6570;&#x503C;&#xFF0C;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> p = <span class="hljs-number">2</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">p</span>) </span>{
  p = <span class="hljs-number">3</span>;
}
f(p);

p <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53D8;&#x91CF;<code>p</code>&#x662F;&#x4E00;&#x4E2A;&#x539F;&#x59CB;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;<code>f</code>&#x7684;&#x65B9;&#x5F0F;&#x662F;&#x4F20;&#x503C;&#x4F20;&#x9012;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#xFF0C;<code>p</code>&#x7684;&#x503C;&#x662F;&#x539F;&#x59CB;&#x503C;&#x7684;&#x62F7;&#x8D1D;&#xFF0C;&#x65E0;&#x8BBA;&#x600E;&#x4E48;&#x4FEE;&#x6539;&#xFF0C;&#x90FD;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x662F;&#x590D;&#x5408;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF08;&#x6570;&#x7EC4;&#x3001;&#x5BF9;&#x8C61;&#x3001;&#x5176;&#x4ED6;&#x51FD;&#x6570;&#xFF09;&#xFF0C;&#x4F20;&#x9012;&#x65B9;&#x5F0F;&#x662F;&#x4F20;&#x5740;&#x4F20;&#x9012;&#xFF08;pass by reference&#xFF09;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;&#x7684;&#x539F;&#x59CB;&#x503C;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x56E0;&#x6B64;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x6539;&#x53C2;&#x6570;&#xFF0C;&#x5C06;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = { p: <span class="hljs-number">1</span> };

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">o</span>) </span>{
  o.p = <span class="hljs-number">2</span>;
}
f(obj);

obj.p <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;<code>f</code>&#x7684;&#x662F;&#x53C2;&#x6570;&#x5BF9;&#x8C61;<code>obj</code>&#x7684;&#x5730;&#x5740;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x6539;<code>obj</code>&#x7684;&#x5C5E;&#x6027;<code>p</code>&#xFF0C;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x6539;&#x7684;&#xFF0C;&#x4E0D;&#x662F;&#x53C2;&#x6570;&#x5BF9;&#x8C61;&#x7684;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x800C;&#x662F;&#x66FF;&#x6362;&#x6389;&#x6574;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x65F6;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> obj = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">o</span>) </span>{
  o = [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];
}
f(obj);

obj <span class="hljs-comment">// [1, 2, 3]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5728;&#x51FD;&#x6570;<code>f</code>&#x5185;&#x90E8;&#xFF0C;&#x53C2;&#x6570;&#x5BF9;&#x8C61;<code>obj</code>&#x88AB;&#x6574;&#x4E2A;&#x66FF;&#x6362;&#x6210;&#x53E6;&#x4E00;&#x4E2A;&#x503C;&#x3002;&#x8FD9;&#x65F6;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x539F;&#x59CB;&#x503C;&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#xFF0C;&#x5F62;&#x5F0F;&#x53C2;&#x6570;&#xFF08;<code>o</code>&#xFF09;&#x7684;&#x503C;&#x5B9E;&#x9645;&#x662F;&#x53C2;&#x6570;<code>obj</code>&#x7684;&#x5730;&#x5740;&#xFF0C;&#x91CD;&#x65B0;&#x5BF9;<code>o</code>&#x8D4B;&#x503C;&#x5BFC;&#x81F4;<code>o</code>&#x6307;&#x5411;&#x53E6;&#x4E00;&#x4E2A;&#x5730;&#x5740;&#xFF0C;&#x4FDD;&#x5B58;&#x5728;&#x539F;&#x5730;&#x5740;&#x4E0A;&#x7684;&#x503C;&#x5F53;&#x7136;&#x4E0D;&#x53D7;&#x5F71;&#x54CD;&#x3002;</p>
<h3 id="&#x540C;&#x540D;&#x53C2;&#x6570;">&#x540C;&#x540D;&#x53C2;&#x6570;</h3>
<p>&#x5982;&#x679C;&#x6709;&#x540C;&#x540D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x53D6;&#x6700;&#x540E;&#x51FA;&#x73B0;&#x7684;&#x90A3;&#x4E2A;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, a</span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>) <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x6709;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E14;&#x53C2;&#x6570;&#x540D;&#x90FD;&#x662F;<code>a</code>&#x3002;&#x53D6;&#x503C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4EE5;&#x540E;&#x9762;&#x7684;<code>a</code>&#x4E3A;&#x51C6;&#xFF0C;&#x5373;&#x4F7F;&#x540E;&#x9762;&#x7684;<code>a</code>&#x6CA1;&#x6709;&#x503C;&#x6216;&#x88AB;&#x7701;&#x7565;&#xFF0C;&#x4E5F;&#x662F;&#x4EE5;&#x5176;&#x4E3A;&#x51C6;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, a</span>) </span>{
  <span class="hljs-built_in">console</span>.log(a);
}

f(<span class="hljs-number">1</span>) <span class="hljs-comment">// undefined</span>
</code></pre>
<p>&#x8C03;&#x7528;&#x51FD;&#x6570;<code>f</code>&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6CA1;&#x6709;&#x63D0;&#x4F9B;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;<code>a</code>&#x7684;&#x53D6;&#x503C;&#x5C31;&#x53D8;&#x6210;&#x4E86;<code>undefined</code>&#x3002;&#x8FD9;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x83B7;&#x5F97;&#x7B2C;&#x4E00;&#x4E2A;<code>a</code>&#x7684;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>arguments</code>&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, a</span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">arguments</span>[<span class="hljs-number">0</span>]);
}

f(<span class="hljs-number">1</span>) <span class="hljs-comment">// 1</span>
</code></pre>
<h3 id="arguments-&#x5BF9;&#x8C61;">arguments &#x5BF9;&#x8C61;</h3>
<p><strong>&#xFF08;1&#xFF09;&#x5B9A;&#x4E49;</strong></p>
<p>&#x7531;&#x4E8E; JavaScript &#x5141;&#x8BB8;&#x51FD;&#x6570;&#x6709;&#x4E0D;&#x5B9A;&#x6570;&#x76EE;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x4E00;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#x8BFB;&#x53D6;&#x6240;&#x6709;&#x53C2;&#x6570;&#x3002;&#x8FD9;&#x5C31;&#x662F;<code>arguments</code>&#x5BF9;&#x8C61;&#x7684;&#x7531;&#x6765;&#x3002;</p>
<p><code>arguments</code>&#x5BF9;&#x8C61;&#x5305;&#x542B;&#x4E86;&#x51FD;&#x6570;&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x6240;&#x6709;&#x53C2;&#x6570;&#xFF0C;<code>arguments[0]</code>&#x5C31;&#x662F;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;<code>arguments[1]</code>&#x5C31;&#x662F;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4EE5;&#x6B64;&#x7C7B;&#x63A8;&#x3002;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x53EA;&#x6709;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x90E8;&#xFF0C;&#x624D;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">one</span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">arguments</span>[<span class="hljs-number">0</span>]);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">arguments</span>[<span class="hljs-number">1</span>]);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">arguments</span>[<span class="hljs-number">2</span>]);
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
<span class="hljs-comment">// 1</span>
<span class="hljs-comment">// 2</span>
<span class="hljs-comment">// 3</span>
</code></pre>
<p>&#x6B63;&#x5E38;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;<code>arguments</code>&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x5728;&#x8FD0;&#x884C;&#x65F6;&#x4FEE;&#x6539;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-built_in">arguments</span>[<span class="hljs-number">0</span>] = <span class="hljs-number">3</span>;
  <span class="hljs-built_in">arguments</span>[<span class="hljs-number">1</span>] = <span class="hljs-number">2</span>;
  <span class="hljs-keyword">return</span> a + b;
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// 5</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x8C03;&#x7528;&#x65F6;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x88AB;&#x4FEE;&#x6539;&#x6210;<code>3</code>&#x548C;<code>2</code>&#x3002;</p>
<p>&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;<code>arguments</code>&#x5BF9;&#x8C61;&#x4E0E;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4E0D;&#x5177;&#x6709;&#x8054;&#x52A8;&#x5173;&#x7CFB;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x4FEE;&#x6539;<code>arguments</code>&#x5BF9;&#x8C61;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x5B9E;&#x9645;&#x7684;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">a, b</span>) </span>{
<span class="hljs-meta">  &apos;use strict&apos;</span>; <span class="hljs-comment">// &#x5F00;&#x542F;&#x4E25;&#x683C;&#x6A21;&#x5F0F;</span>
  <span class="hljs-built_in">arguments</span>[<span class="hljs-number">0</span>] = <span class="hljs-number">3</span>;
  <span class="hljs-built_in">arguments</span>[<span class="hljs-number">1</span>] = <span class="hljs-number">2</span>;
  <span class="hljs-keyword">return</span> a + b;
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>) <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x662F;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#xFF0C;&#x8FD9;&#x65F6;&#x4FEE;&#x6539;<code>arguments</code>&#x5BF9;&#x8C61;&#xFF0C;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x771F;&#x5B9E;&#x53C2;&#x6570;<code>a</code>&#x548C;<code>b</code>&#x3002;</p>
<p>&#x901A;&#x8FC7;<code>arguments</code>&#x5BF9;&#x8C61;&#x7684;<code>length</code>&#x5C5E;&#x6027;&#xFF0C;&#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65F6;&#x5230;&#x5E95;&#x5E26;&#x51E0;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-built_in">arguments</span>.length;
}

f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>) <span class="hljs-comment">// 3</span>
f(<span class="hljs-number">1</span>) <span class="hljs-comment">// 1</span>
f() <span class="hljs-comment">// 0</span>
</code></pre>
<p><strong>&#xFF08;2&#xFF09;&#x4E0E;&#x6570;&#x7EC4;&#x7684;&#x5173;&#x7CFB;</strong></p>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x867D;&#x7136;<code>arguments</code>&#x5F88;&#x50CF;&#x6570;&#x7EC4;&#xFF0C;&#x4F46;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;&#x6570;&#x7EC4;&#x4E13;&#x6709;&#x7684;&#x65B9;&#x6CD5;&#xFF08;&#x6BD4;&#x5982;<code>slice</code>&#x548C;<code>forEach</code>&#xFF09;&#xFF0C;&#x4E0D;&#x80FD;&#x5728;<code>arguments</code>&#x5BF9;&#x8C61;&#x4E0A;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x3002;</p>
<p>&#x5982;&#x679C;&#x8981;&#x8BA9;<code>arguments</code>&#x5BF9;&#x8C61;&#x4F7F;&#x7528;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#xFF0C;&#x771F;&#x6B63;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x662F;&#x5C06;<code>arguments</code>&#x8F6C;&#x4E3A;&#x771F;&#x6B63;&#x7684;&#x6570;&#x7EC4;&#x3002;&#x4E0B;&#x9762;&#x662F;&#x4E24;&#x79CD;&#x5E38;&#x7528;&#x7684;&#x8F6C;&#x6362;&#x65B9;&#x6CD5;&#xFF1A;<code>slice</code>&#x65B9;&#x6CD5;&#x548C;&#x9010;&#x4E00;&#x586B;&#x5165;&#x65B0;&#x6570;&#x7EC4;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> args = <span class="hljs-built_in">Array</span>.prototype.slice.call(<span class="hljs-built_in">arguments</span>);

<span class="hljs-comment">// &#x6216;&#x8005;</span>
<span class="hljs-keyword">var</span> args = [];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-built_in">arguments</span>.length; i++) {
  args.push(<span class="hljs-built_in">arguments</span>[i]);
}
</code></pre>
<p><strong>&#xFF08;3&#xFF09;callee &#x5C5E;&#x6027;</strong></p>
<p><code>arguments</code>&#x5BF9;&#x8C61;&#x5E26;&#x6709;&#x4E00;&#x4E2A;<code>callee</code>&#x5C5E;&#x6027;&#xFF0C;&#x8FD4;&#x56DE;&#x5B83;&#x6240;&#x5BF9;&#x5E94;&#x7684;&#x539F;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">arguments</span>.callee === f);
}

f() <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>arguments.callee</code>&#xFF0C;&#x8FBE;&#x5230;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x81EA;&#x8EAB;&#x7684;&#x76EE;&#x7684;&#x3002;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x91CC;&#x9762;&#x662F;&#x7981;&#x7528;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x3002;</p>
<h2 id="&#x51FD;&#x6570;&#x7684;&#x5176;&#x4ED6;&#x77E5;&#x8BC6;&#x70B9;">&#x51FD;&#x6570;&#x7684;&#x5176;&#x4ED6;&#x77E5;&#x8BC6;&#x70B9;</h2>
<h3 id="&#x95ED;&#x5305;">&#x95ED;&#x5305;</h3>
<p>&#x95ED;&#x5305;&#xFF08;closure&#xFF09;&#x662F; JavaScript &#x8BED;&#x8A00;&#x7684;&#x4E00;&#x4E2A;&#x96BE;&#x70B9;&#xFF0C;&#x4E5F;&#x662F;&#x5B83;&#x7684;&#x7279;&#x8272;&#xFF0C;&#x5F88;&#x591A;&#x9AD8;&#x7EA7;&#x5E94;&#x7528;&#x90FD;&#x8981;&#x4F9D;&#x9760;&#x95ED;&#x5305;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x7406;&#x89E3;&#x95ED;&#x5305;&#xFF0C;&#x9996;&#x5148;&#x5FC5;&#x987B;&#x7406;&#x89E3;&#x53D8;&#x91CF;&#x4F5C;&#x7528;&#x57DF;&#x3002;&#x524D;&#x9762;&#x63D0;&#x5230;&#xFF0C;JavaScript &#x6709;&#x4E24;&#x79CD;&#x4F5C;&#x7528;&#x57DF;&#xFF1A;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x548C;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x3002;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8BFB;&#x53D6;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> n = <span class="hljs-number">999</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(n);
}
f1() <span class="hljs-comment">// 999</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f1</code>&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#x5168;&#x5C40;&#x53D8;&#x91CF;<code>n</code>&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> n = <span class="hljs-number">999</span>;
}

<span class="hljs-built_in">console</span>.log(n)
<span class="hljs-comment">// Uncaught ReferenceError: n is not defined(</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f1</code>&#x5185;&#x90E8;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;<code>n</code>&#xFF0C;&#x51FD;&#x6570;&#x5916;&#x662F;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#x7684;&#x3002;</p>
<p>&#x5982;&#x679C;&#x51FA;&#x4E8E;&#x79CD;&#x79CD;&#x539F;&#x56E0;&#xFF0C;&#x9700;&#x8981;&#x5F97;&#x5230;&#x51FD;&#x6570;&#x5185;&#x7684;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x3002;&#x6B63;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8FD9;&#x662F;&#x529E;&#x4E0D;&#x5230;&#x7684;&#xFF0C;&#x53EA;&#x6709;&#x901A;&#x8FC7;&#x53D8;&#x901A;&#x65B9;&#x6CD5;&#x624D;&#x80FD;&#x5B9E;&#x73B0;&#x3002;&#x90A3;&#x5C31;&#x662F;&#x5728;&#x51FD;&#x6570;&#x7684;&#x5185;&#x90E8;&#xFF0C;&#x518D;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> n = <span class="hljs-number">999</span>;
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f2</span>(<span class="hljs-params"></span>) </span>{
&#x3000;&#x3000;<span class="hljs-built_in">console</span>.log(n); <span class="hljs-comment">// 999</span>
  }
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f2</code>&#x5C31;&#x5728;&#x51FD;&#x6570;<code>f1</code>&#x5185;&#x90E8;&#xFF0C;&#x8FD9;&#x65F6;<code>f1</code>&#x5185;&#x90E8;&#x7684;&#x6240;&#x6709;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x5BF9;<code>f2</code>&#x90FD;&#x662F;&#x53EF;&#x89C1;&#x7684;&#x3002;&#x4F46;&#x662F;&#x53CD;&#x8FC7;&#x6765;&#x5C31;&#x4E0D;&#x884C;&#xFF0C;<code>f2</code>&#x5185;&#x90E8;&#x7684;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x5BF9;<code>f1</code>&#x5C31;&#x662F;&#x4E0D;&#x53EF;&#x89C1;&#x7684;&#x3002;&#x8FD9;&#x5C31;&#x662F; JavaScript &#x8BED;&#x8A00;&#x7279;&#x6709;&#x7684;&quot;&#x94FE;&#x5F0F;&#x4F5C;&#x7528;&#x57DF;&quot;&#x7ED3;&#x6784;&#xFF08;chain scope&#xFF09;&#xFF0C;&#x5B50;&#x5BF9;&#x8C61;&#x4F1A;&#x4E00;&#x7EA7;&#x4E00;&#x7EA7;&#x5730;&#x5411;&#x4E0A;&#x5BFB;&#x627E;&#x6240;&#x6709;&#x7236;&#x5BF9;&#x8C61;&#x7684;&#x53D8;&#x91CF;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x7236;&#x5BF9;&#x8C61;&#x7684;&#x6240;&#x6709;&#x53D8;&#x91CF;&#xFF0C;&#x5BF9;&#x5B50;&#x5BF9;&#x8C61;&#x90FD;&#x662F;&#x53EF;&#x89C1;&#x7684;&#xFF0C;&#x53CD;&#x4E4B;&#x5219;&#x4E0D;&#x6210;&#x7ACB;&#x3002;</p>
<p>&#x65E2;&#x7136;<code>f2</code>&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;<code>f1</code>&#x7684;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x90A3;&#x4E48;&#x53EA;&#x8981;&#x628A;<code>f2</code>&#x4F5C;&#x4E3A;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x5C31;&#x53EF;&#x4EE5;&#x5728;<code>f1</code>&#x5916;&#x90E8;&#x8BFB;&#x53D6;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x4E86;&#x5417;&#xFF01;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f1</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> n = <span class="hljs-number">999</span>;
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f2</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(n);
  }
  <span class="hljs-keyword">return</span> f2;
}

<span class="hljs-keyword">var</span> result = f1();
result(); <span class="hljs-comment">// 999</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f1</code>&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x5C31;&#x662F;&#x51FD;&#x6570;<code>f2</code>&#xFF0C;&#x7531;&#x4E8E;<code>f2</code>&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;<code>f1</code>&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x5916;&#x90E8;&#x83B7;&#x5F97;<code>f1</code>&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x4E86;&#x3002;</p>
<p>&#x95ED;&#x5305;&#x5C31;&#x662F;&#x51FD;&#x6570;<code>f2</code>&#xFF0C;&#x5373;&#x80FD;&#x591F;&#x8BFB;&#x53D6;&#x5176;&#x4ED6;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x7684;&#x51FD;&#x6570;&#x3002;&#x7531;&#x4E8E;&#x5728; JavaScript &#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x53EA;&#x6709;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x5B50;&#x51FD;&#x6570;&#x624D;&#x80FD;&#x8BFB;&#x53D6;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x628A;&#x95ED;&#x5305;&#x7B80;&#x5355;&#x7406;&#x89E3;&#x6210;&#x201C;&#x5B9A;&#x4E49;&#x5728;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x51FD;&#x6570;&#x201D;&#x3002;&#x95ED;&#x5305;&#x6700;&#x5927;&#x7684;&#x7279;&#x70B9;&#xFF0C;&#x5C31;&#x662F;&#x5B83;&#x53EF;&#x4EE5;&#x201C;&#x8BB0;&#x4F4F;&#x201D;&#x8BDE;&#x751F;&#x7684;&#x73AF;&#x5883;&#xFF0C;&#x6BD4;&#x5982;<code>f2</code>&#x8BB0;&#x4F4F;&#x4E86;&#x5B83;&#x8BDE;&#x751F;&#x7684;&#x73AF;&#x5883;<code>f1</code>&#xFF0C;&#x6240;&#x4EE5;&#x4ECE;<code>f2</code>&#x53EF;&#x4EE5;&#x5F97;&#x5230;<code>f1</code>&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x3002;&#x5728;&#x672C;&#x8D28;&#x4E0A;&#xFF0C;&#x95ED;&#x5305;&#x5C31;&#x662F;&#x5C06;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x548C;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x8FDE;&#x63A5;&#x8D77;&#x6765;&#x7684;&#x4E00;&#x5EA7;&#x6865;&#x6881;&#x3002;</p>
<p>&#x95ED;&#x5305;&#x7684;&#x6700;&#x5927;&#x7528;&#x5904;&#x6709;&#x4E24;&#x4E2A;&#xFF0C;&#x4E00;&#x4E2A;&#x662F;&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x53E6;&#x4E00;&#x4E2A;&#x5C31;&#x662F;&#x8BA9;&#x8FD9;&#x4E9B;&#x53D8;&#x91CF;&#x59CB;&#x7EC8;&#x4FDD;&#x6301;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x5373;&#x95ED;&#x5305;&#x53EF;&#x4EE5;&#x4F7F;&#x5F97;&#x5B83;&#x8BDE;&#x751F;&#x73AF;&#x5883;&#x4E00;&#x76F4;&#x5B58;&#x5728;&#x3002;&#x8BF7;&#x770B;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x95ED;&#x5305;&#x4F7F;&#x5F97;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x8BB0;&#x4F4F;&#x4E0A;&#x4E00;&#x6B21;&#x8C03;&#x7528;&#x65F6;&#x7684;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createIncrementor</span>(<span class="hljs-params">start</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> start++;
  };
}

<span class="hljs-keyword">var</span> inc = createIncrementor(<span class="hljs-number">5</span>);

inc() <span class="hljs-comment">// 5</span>
inc() <span class="hljs-comment">// 6</span>
inc() <span class="hljs-comment">// 7</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>start</code>&#x662F;&#x51FD;&#x6570;<code>createIncrementor</code>&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#x3002;&#x901A;&#x8FC7;&#x95ED;&#x5305;&#xFF0C;<code>start</code>&#x7684;&#x72B6;&#x6001;&#x88AB;&#x4FDD;&#x7559;&#x4E86;&#xFF0C;&#x6BCF;&#x4E00;&#x6B21;&#x8C03;&#x7528;&#x90FD;&#x662F;&#x5728;&#x4E0A;&#x4E00;&#x6B21;&#x8C03;&#x7528;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x8FDB;&#x884C;&#x8BA1;&#x7B97;&#x3002;&#x4ECE;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x95ED;&#x5305;<code>inc</code>&#x4F7F;&#x5F97;&#x51FD;&#x6570;<code>createIncrementor</code>&#x7684;&#x5185;&#x90E8;&#x73AF;&#x5883;&#xFF0C;&#x4E00;&#x76F4;&#x5B58;&#x5728;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x95ED;&#x5305;&#x53EF;&#x4EE5;&#x770B;&#x4F5C;&#x662F;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x3002;</p>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x8FD9;&#x6837;&#x5462;&#xFF1F;&#x539F;&#x56E0;&#x5C31;&#x5728;&#x4E8E;<code>inc</code>&#x59CB;&#x7EC8;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x800C;<code>inc</code>&#x7684;&#x5B58;&#x5728;&#x4F9D;&#x8D56;&#x4E8E;<code>createIncrementor</code>&#xFF0C;&#x56E0;&#x6B64;&#x4E5F;&#x59CB;&#x7EC8;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x4E0D;&#x4F1A;&#x5728;&#x8C03;&#x7528;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x88AB;&#x5783;&#x573E;&#x56DE;&#x6536;&#x673A;&#x5236;&#x56DE;&#x6536;&#x3002;</p>
<p>&#x95ED;&#x5305;&#x7684;&#x53E6;&#x4E00;&#x4E2A;&#x7528;&#x5904;&#xFF0C;&#x662F;&#x5C01;&#x88C5;&#x5BF9;&#x8C61;&#x7684;&#x79C1;&#x6709;&#x5C5E;&#x6027;&#x548C;&#x79C1;&#x6709;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">var</span> _age;
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setAge</span>(<span class="hljs-params">n</span>) </span>{
    _age = n;
  }
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getAge</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> _age;
  }

  <span class="hljs-keyword">return</span> {
    name: name,
    getAge: getAge,
    setAge: setAge
  };
}

<span class="hljs-keyword">var</span> p1 = Person(<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>);
p1.setAge(<span class="hljs-number">25</span>);
p1.getAge() <span class="hljs-comment">// 25</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>Person</code>&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;<code>_age</code>&#xFF0C;&#x901A;&#x8FC7;&#x95ED;&#x5305;<code>getAge</code>&#x548C;<code>setAge</code>&#xFF0C;&#x53D8;&#x6210;&#x4E86;&#x8FD4;&#x56DE;&#x5BF9;&#x8C61;<code>p1</code>&#x7684;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5916;&#x5C42;&#x51FD;&#x6570;&#x6BCF;&#x6B21;&#x8FD0;&#x884C;&#xFF0C;&#x90FD;&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x95ED;&#x5305;&#xFF0C;&#x800C;&#x8FD9;&#x4E2A;&#x95ED;&#x5305;&#x53C8;&#x4F1A;&#x4FDD;&#x7559;&#x5916;&#x5C42;&#x51FD;&#x6570;&#x7684;&#x5185;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x6240;&#x4EE5;&#x5185;&#x5B58;&#x6D88;&#x8017;&#x5F88;&#x5927;&#x3002;&#x56E0;&#x6B64;&#x4E0D;&#x80FD;&#x6EE5;&#x7528;&#x95ED;&#x5305;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x9020;&#x6210;&#x7F51;&#x9875;&#x7684;&#x6027;&#x80FD;&#x95EE;&#x9898;&#x3002;</p>
<h3 id="&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;iife&#xFF09;">&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#xFF08;IIFE&#xFF09;</h3>
<p>&#x5728; JavaScript &#x4E2D;&#xFF0C;&#x5706;&#x62EC;&#x53F7;<code>()</code>&#x662F;&#x4E00;&#x79CD;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x8DDF;&#x5728;&#x51FD;&#x6570;&#x540D;&#x4E4B;&#x540E;&#xFF0C;&#x8868;&#x793A;&#x8C03;&#x7528;&#x8BE5;&#x51FD;&#x6570;&#x3002;&#x6BD4;&#x5982;&#xFF0C;<code>print()</code>&#x5C31;&#x8868;&#x793A;&#x8C03;&#x7528;<code>print</code>&#x51FD;&#x6570;&#x3002;</p>
<p>&#x6709;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x4E4B;&#x540E;&#xFF0C;&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x8BE5;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x65F6;&#xFF0C;&#x4F60;&#x4E0D;&#x80FD;&#x5728;&#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49;&#x4E4B;&#x540E;&#x52A0;&#x4E0A;&#x5706;&#x62EC;&#x53F7;&#xFF0C;&#x8FD9;&#x4F1A;&#x4EA7;&#x751F;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }();
<span class="hljs-comment">// SyntaxError: Unexpected token (</span>
</code></pre>
<p>&#x4EA7;&#x751F;&#x8FD9;&#x4E2A;&#x9519;&#x8BEF;&#x7684;&#x539F;&#x56E0;&#x662F;&#xFF0C;<code>function</code>&#x8FD9;&#x4E2A;&#x5173;&#x952E;&#x5B57;&#x5373;&#x53EF;&#x4EE5;&#x5F53;&#x4F5C;&#x8BED;&#x53E5;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5F53;&#x4F5C;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x8BED;&#x53E5;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}

<span class="hljs-comment">// &#x8868;&#x8FBE;&#x5F0F;</span>
<span class="hljs-keyword">var</span> f = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{}
</code></pre>
<p>&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x89E3;&#x6790;&#x4E0A;&#x7684;&#x6B67;&#x4E49;&#xFF0C;JavaScript &#x5F15;&#x64CE;&#x89C4;&#x5B9A;&#xFF0C;&#x5982;&#x679C;<code>function</code>&#x5173;&#x952E;&#x5B57;&#x51FA;&#x73B0;&#x5728;&#x884C;&#x9996;&#xFF0C;&#x4E00;&#x5F8B;&#x89E3;&#x91CA;&#x6210;&#x8BED;&#x53E5;&#x3002;&#x56E0;&#x6B64;&#xFF0C;JavaScript &#x5F15;&#x64CE;&#x770B;&#x5230;&#x884C;&#x9996;&#x662F;<code>function</code>&#x5173;&#x952E;&#x5B57;&#x4E4B;&#x540E;&#xFF0C;&#x8BA4;&#x4E3A;&#x8FD9;&#x4E00;&#x6BB5;&#x90FD;&#x662F;&#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49;&#xFF0C;&#x4E0D;&#x5E94;&#x8BE5;&#x4EE5;&#x5706;&#x62EC;&#x53F7;&#x7ED3;&#x5C3E;&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x62A5;&#x9519;&#x4E86;&#x3002;</p>
<p>&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x4E0D;&#x8981;&#x8BA9;<code>function</code>&#x51FA;&#x73B0;&#x5728;&#x884C;&#x9996;&#xFF0C;&#x8BA9;&#x5F15;&#x64CE;&#x5C06;&#x5176;&#x7406;&#x89E3;&#x6210;&#x4E00;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x3002;&#x6700;&#x7B80;&#x5355;&#x7684;&#x5904;&#x7406;&#xFF0C;&#x5C31;&#x662F;&#x5C06;&#x5176;&#x653E;&#x5728;&#x4E00;&#x4E2A;&#x5706;&#x62EC;&#x53F7;&#x91CC;&#x9762;&#x3002;</p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }());
<span class="hljs-comment">// &#x6216;&#x8005;</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> })();
</code></pre>
<p>&#x4E0A;&#x9762;&#x4E24;&#x79CD;&#x5199;&#x6CD5;&#x90FD;&#x662F;&#x4EE5;&#x5706;&#x62EC;&#x53F7;&#x5F00;&#x5934;&#xFF0C;&#x5F15;&#x64CE;&#x5C31;&#x4F1A;&#x8BA4;&#x4E3A;&#x540E;&#x9762;&#x8DDF;&#x7684;&#x662F;&#x4E00;&#x4E2A;&#x8868;&#x793A;&#x5F0F;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x8BED;&#x53E5;&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x907F;&#x514D;&#x4E86;&#x9519;&#x8BEF;&#x3002;&#x8FD9;&#x5C31;&#x53EB;&#x505A;&#x201C;&#x7ACB;&#x5373;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x201D;&#xFF08;Immediately-Invoked Function Expression&#xFF09;&#xFF0C;&#x7B80;&#x79F0; IIFE&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x4E0A;&#x9762;&#x4E24;&#x79CD;&#x5199;&#x6CD5;&#x6700;&#x540E;&#x7684;&#x5206;&#x53F7;&#x90FD;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;&#x5982;&#x679C;&#x7701;&#x7565;&#x5206;&#x53F7;&#xFF0C;&#x9047;&#x5230;&#x8FDE;&#x7740;&#x4E24;&#x4E2A; IIFE&#xFF0C;&#x53EF;&#x80FD;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x62A5;&#x9519;</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }())
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }())
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x4E24;&#x884C;&#x4E4B;&#x95F4;&#x6CA1;&#x6709;&#x5206;&#x53F7;&#xFF0C;JavaScript &#x4F1A;&#x5C06;&#x5B83;&#x4EEC;&#x8FDE;&#x5728;&#x4E00;&#x8D77;&#x89E3;&#x91CA;&#xFF0C;&#x5C06;&#x7B2C;&#x4E8C;&#x884C;&#x89E3;&#x91CA;&#x4E3A;&#x7B2C;&#x4E00;&#x884C;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x63A8;&#x800C;&#x5E7F;&#x4E4B;&#xFF0C;&#x4EFB;&#x4F55;&#x8BA9;&#x89E3;&#x91CA;&#x5668;&#x4EE5;&#x8868;&#x8FBE;&#x5F0F;&#x6765;&#x5904;&#x7406;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x90FD;&#x80FD;&#x4EA7;&#x751F;&#x540C;&#x6837;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x6BD4;&#x5982;&#x4E0B;&#x9762;&#x4E09;&#x79CD;&#x5199;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> i = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-keyword">return</span> <span class="hljs-number">10</span>; }();
<span class="hljs-literal">true</span> &amp;&amp; <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }();
<span class="hljs-number">0</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{ <span class="hljs-comment">/* code */</span> }();
</code></pre>
<p>&#x751A;&#x81F3;&#x50CF;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x5199;&#xFF0C;&#x4E5F;&#x662F;&#x53EF;&#x4EE5;&#x7684;&#x3002;</p>
<pre><code class="lang-javascript">!<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
~<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
-<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
+<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* code */</span> }();
</code></pre>
<p>&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x53EA;&#x5BF9;&#x533F;&#x540D;&#x51FD;&#x6570;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x201C;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;&#x201D;&#x3002;&#x5B83;&#x7684;&#x76EE;&#x7684;&#x6709;&#x4E24;&#x4E2A;&#xFF1A;&#x4E00;&#x662F;&#x4E0D;&#x5FC5;&#x4E3A;&#x51FD;&#x6570;&#x547D;&#x540D;&#xFF0C;&#x907F;&#x514D;&#x4E86;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF1B;&#x4E8C;&#x662F; IIFE &#x5185;&#x90E8;&#x5F62;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x53EF;&#x4EE5;&#x5C01;&#x88C5;&#x4E00;&#x4E9B;&#x5916;&#x90E8;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#x7684;&#x79C1;&#x6709;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x5199;&#x6CD5;&#x4E00;</span>
<span class="hljs-keyword">var</span> tmp = newData;
processData(tmp);
storeData(tmp);

<span class="hljs-comment">// &#x5199;&#x6CD5;&#x4E8C;</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> tmp = newData;
  processData(tmp);
  storeData(tmp);
}());
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5199;&#x6CD5;&#x4E8C;&#x6BD4;&#x5199;&#x6CD5;&#x4E00;&#x66F4;&#x597D;&#xFF0C;&#x56E0;&#x4E3A;&#x5B8C;&#x5168;&#x907F;&#x514D;&#x4E86;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;</p>
<h2 id="eval-&#x547D;&#x4EE4;">eval &#x547D;&#x4EE4;</h2>
<h3 id="&#x57FA;&#x672C;&#x7528;&#x6CD5;">&#x57FA;&#x672C;&#x7528;&#x6CD5;</h3>
<p><code>eval</code>&#x547D;&#x4EE4;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x5E76;&#x5C06;&#x8FD9;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x5F53;&#x4F5C;&#x8BED;&#x53E5;&#x6267;&#x884C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">eval</span>(<span class="hljs-string">&apos;var a = 1;&apos;</span>);
a <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5C06;&#x5B57;&#x7B26;&#x4E32;&#x5F53;&#x4F5C;&#x8BED;&#x53E5;&#x8FD0;&#x884C;&#xFF0C;&#x751F;&#x6210;&#x4E86;&#x53D8;&#x91CF;<code>a</code>&#x3002;</p>
<p>&#x5982;&#x679C;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x65E0;&#x6CD5;&#x5F53;&#x4F5C;&#x8BED;&#x53E5;&#x8FD0;&#x884C;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">eval</span>(<span class="hljs-string">&apos;3x&apos;</span>) <span class="hljs-comment">// Uncaught SyntaxError: Invalid or unexpected token</span>
</code></pre>
<p>&#x653E;&#x5728;<code>eval</code>&#x4E2D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E94;&#x8BE5;&#x6709;&#x72EC;&#x81EA;&#x5B58;&#x5728;&#x7684;&#x610F;&#x4E49;&#xFF0C;&#x4E0D;&#x80FD;&#x7528;&#x6765;&#x4E0E;<code>eval</code>&#x4EE5;&#x5916;&#x7684;&#x547D;&#x4EE4;&#x914D;&#x5408;&#x4F7F;&#x7528;&#x3002;&#x4E3E;&#x4F8B;&#x6765;&#x8BF4;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x5C06;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">eval</span>(<span class="hljs-string">&apos;return;&apos;</span>); <span class="hljs-comment">// Uncaught SyntaxError: Illegal return statement</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x4E3A;<code>return</code>&#x4E0D;&#x80FD;&#x5355;&#x72EC;&#x4F7F;&#x7528;&#xFF0C;&#x5FC5;&#x987B;&#x5728;&#x51FD;&#x6570;&#x4E2D;&#x4F7F;&#x7528;&#x3002;</p>
<p>&#x5982;&#x679C;<code>eval</code>&#x7684;&#x53C2;&#x6570;&#x4E0D;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x90A3;&#x4E48;&#x4F1A;&#x539F;&#x6837;&#x8FD4;&#x56DE;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">eval</span>(<span class="hljs-number">123</span>) <span class="hljs-comment">// 123</span>
</code></pre>
<p><code>eval</code>&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x90FD;&#x5728;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x6267;&#x884C;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x80FD;&#x4F1A;&#x4FEE;&#x6539;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x53D8;&#x91CF;&#x7684;&#x503C;&#xFF0C;&#x9020;&#x6210;&#x5B89;&#x5168;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;
<span class="hljs-built_in">eval</span>(<span class="hljs-string">&apos;a = 2&apos;</span>);

a <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>eval</code>&#x547D;&#x4EE4;&#x4FEE;&#x6539;&#x4E86;&#x5916;&#x90E8;&#x53D8;&#x91CF;<code>a</code>&#x7684;&#x503C;&#x3002;&#x7531;&#x4E8E;&#x8FD9;&#x4E2A;&#x539F;&#x56E0;&#xFF0C;<code>eval</code>&#x6709;&#x5B89;&#x5168;&#x98CE;&#x9669;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x9632;&#x6B62;&#x8FD9;&#x79CD;&#x98CE;&#x9669;&#xFF0C;JavaScript &#x89C4;&#x5B9A;&#xFF0C;&#x5982;&#x679C;&#x4F7F;&#x7528;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#xFF0C;<code>eval</code>&#x5185;&#x90E8;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x5916;&#x90E8;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-meta">  &apos;use strict&apos;</span>;
  <span class="hljs-built_in">eval</span>(<span class="hljs-string">&apos;var foo = 123&apos;</span>);
  <span class="hljs-built_in">console</span>.log(foo);  <span class="hljs-comment">// ReferenceError: foo is not defined</span>
})()
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>f</code>&#x5185;&#x90E8;&#x662F;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#xFF0C;&#x8FD9;&#x65F6;<code>eval</code>&#x5185;&#x90E8;&#x58F0;&#x660E;&#x7684;<code>foo</code>&#x53D8;&#x91CF;&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x5230;&#x5916;&#x90E8;&#x3002;</p>
<p>&#x4E0D;&#x8FC7;&#xFF0C;&#x5373;&#x4F7F;&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;<code>eval</code>&#x4F9D;&#x7136;&#x53EF;&#x4EE5;&#x8BFB;&#x5199;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript">(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-meta">  &apos;use strict&apos;</span>;
  <span class="hljs-keyword">var</span> foo = <span class="hljs-number">1</span>;
  <span class="hljs-built_in">eval</span>(<span class="hljs-string">&apos;foo = 2&apos;</span>);
  <span class="hljs-built_in">console</span>.log(foo);  <span class="hljs-comment">// 2</span>
})()
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x4E25;&#x683C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;<code>eval</code>&#x5185;&#x90E8;&#x8FD8;&#x662F;&#x6539;&#x5199;&#x4E86;&#x5916;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x53EF;&#x89C1;&#x5B89;&#x5168;&#x98CE;&#x9669;&#x4F9D;&#x7136;&#x5B58;&#x5728;&#x3002;</p>
<p>&#x603B;&#x4E4B;&#xFF0C;<code>eval</code>&#x7684;&#x672C;&#x8D28;&#x662F;&#x5728;&#x5F53;&#x524D;&#x4F5C;&#x7528;&#x57DF;&#x4E4B;&#x4E2D;&#xFF0C;&#x6CE8;&#x5165;&#x4EE3;&#x7801;&#x3002;&#x7531;&#x4E8E;&#x5B89;&#x5168;&#x98CE;&#x9669;&#x548C;&#x4E0D;&#x5229;&#x4E8E; JavaScript &#x5F15;&#x64CE;&#x4F18;&#x5316;&#x6267;&#x884C;&#x901F;&#x5EA6;&#xFF0C;&#x6240;&#x4EE5;&#x4E00;&#x822C;&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x3002;&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;<code>eval</code>&#x6700;&#x5E38;&#x89C1;&#x7684;&#x573A;&#x5408;&#x662F;&#x89E3;&#x6790; JSON &#x6570;&#x636E;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4E0D;&#x8FC7;&#x6B63;&#x786E;&#x7684;&#x505A;&#x6CD5;&#x5E94;&#x8BE5;&#x662F;&#x4F7F;&#x7528;&#x539F;&#x751F;&#x7684;<code>JSON.parse</code>&#x65B9;&#x6CD5;&#x3002;</p>
<h3 id="eval-&#x7684;&#x522B;&#x540D;&#x8C03;&#x7528;">eval &#x7684;&#x522B;&#x540D;&#x8C03;&#x7528;</h3>
<p>&#x524D;&#x9762;&#x8BF4;&#x8FC7;<code>eval</code>&#x4E0D;&#x5229;&#x4E8E;&#x5F15;&#x64CE;&#x4F18;&#x5316;&#x6267;&#x884C;&#x901F;&#x5EA6;&#x3002;&#x66F4;&#x9EBB;&#x70E6;&#x7684;&#x662F;&#xFF0C;&#x8FD8;&#x6709;&#x4E0B;&#x9762;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x5F15;&#x64CE;&#x5728;&#x9759;&#x6001;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x7684;&#x9636;&#x6BB5;&#xFF0C;&#x6839;&#x672C;&#x65E0;&#x6CD5;&#x5206;&#x8FA8;&#x6267;&#x884C;&#x7684;&#x662F;<code>eval</code>&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> m = <span class="hljs-built_in">eval</span>;
m(<span class="hljs-string">&apos;var x = 1&apos;</span>);
x <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53D8;&#x91CF;<code>m</code>&#x662F;<code>eval</code>&#x7684;&#x522B;&#x540D;&#x3002;&#x9759;&#x6001;&#x4EE3;&#x7801;&#x5206;&#x6790;&#x9636;&#x6BB5;&#xFF0C;&#x5F15;&#x64CE;&#x5206;&#x8FA8;&#x4E0D;&#x51FA;<code>m(&apos;var x = 1&apos;)</code>&#x6267;&#x884C;&#x7684;&#x662F;<code>eval</code>&#x547D;&#x4EE4;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x4FDD;&#x8BC1;<code>eval</code>&#x7684;&#x522B;&#x540D;&#x4E0D;&#x5F71;&#x54CD;&#x4EE3;&#x7801;&#x4F18;&#x5316;&#xFF0C;JavaScript &#x7684;&#x6807;&#x51C6;&#x89C4;&#x5B9A;&#xFF0C;&#x51E1;&#x662F;&#x4F7F;&#x7528;&#x522B;&#x540D;&#x6267;&#x884C;<code>eval</code>&#xFF0C;<code>eval</code>&#x5185;&#x90E8;&#x4E00;&#x5F8B;&#x662F;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> a = <span class="hljs-number">2</span>;
  <span class="hljs-keyword">var</span> e = <span class="hljs-built_in">eval</span>;
  e(<span class="hljs-string">&apos;console.log(a)&apos;</span>);
}

f() <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>eval</code>&#x662F;&#x522B;&#x540D;&#x8C03;&#x7528;&#xFF0C;&#x6240;&#x4EE5;&#x5373;&#x4F7F;&#x5B83;&#x662F;&#x5728;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x8FD8;&#x662F;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x56E0;&#x6B64;&#x8F93;&#x51FA;&#x7684;<code>a</code>&#x4E3A;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#xFF0C;&#x5F15;&#x64CE;&#x5C31;&#x80FD;&#x786E;&#x8BA4;<code>e()</code>&#x4E0D;&#x4F1A;&#x5BF9;&#x5F53;&#x524D;&#x7684;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x57DF;&#x4EA7;&#x751F;&#x5F71;&#x54CD;&#xFF0C;&#x4F18;&#x5316;&#x7684;&#x65F6;&#x5019;&#x5C31;&#x53EF;&#x4EE5;&#x628A;&#x8FD9;&#x4E00;&#x884C;&#x6392;&#x9664;&#x6389;&#x3002;</p>
<p><code>eval</code>&#x7684;&#x522B;&#x540D;&#x8C03;&#x7528;&#x7684;&#x5F62;&#x5F0F;&#x4E94;&#x82B1;&#x516B;&#x95E8;&#xFF0C;&#x53EA;&#x8981;&#x4E0D;&#x662F;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#xFF0C;&#x90FD;&#x5C5E;&#x4E8E;&#x522B;&#x540D;&#x8C03;&#x7528;&#xFF0C;&#x56E0;&#x4E3A;&#x5F15;&#x64CE;&#x53EA;&#x80FD;&#x5206;&#x8FA8;<code>eval()</code>&#x8FD9;&#x4E00;&#x79CD;&#x5F62;&#x5F0F;&#x662F;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">eval</span>.call(<span class="hljs-literal">null</span>, <span class="hljs-string">&apos;...&apos;</span>)
<span class="hljs-built_in">window</span>.eval(<span class="hljs-string">&apos;...&apos;</span>)
(<span class="hljs-number">1</span>, <span class="hljs-built_in">eval</span>)(<span class="hljs-string">&apos;...&apos;</span>)
(<span class="hljs-built_in">eval</span>, <span class="hljs-built_in">eval</span>)(<span class="hljs-string">&apos;...&apos;</span>)
</code></pre>
<p>&#x4E0A;&#x9762;&#x8FD9;&#x4E9B;&#x5F62;&#x5F0F;&#x90FD;&#x662F;<code>eval</code>&#x7684;&#x522B;&#x540D;&#x8C03;&#x7528;&#xFF0C;&#x4F5C;&#x7528;&#x57DF;&#x90FD;&#x662F;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<h2 id="&#x53C2;&#x8003;&#x94FE;&#x63A5;">&#x53C2;&#x8003;&#x94FE;&#x63A5;</h2>
<ul>
<li>Ben Alman, <a href="http://benalman.com/news/2010/11/immediately-invoked-function-expression/" target="_blank" rel="nofollow">Immediately-Invoked Function Expression (IIFE)</a></li>
<li>Mark Daggett, <a href="http://markdaggett.com/blog/2013/02/15/functions-explained/" target="_blank" rel="nofollow">Functions Explained</a></li>
<li>Juriy Zaytsev, <a href="http://kangax.github.com/nfe/" target="_blank" rel="nofollow">Named function expressions demystified</a></li>
<li>Marco Rogers polotek, <a href="http://docs.nodejitsu.com/articles/javascript-conventions/what-is-the-arguments-object" target="_blank" rel="nofollow">What is the arguments object?</a></li>
<li>Juriy Zaytsev, <a href="http://perfectionkills.com/global-eval-what-are-the-options/" target="_blank" rel="nofollow">Global eval. What are the options?</a></li>
<li>Axel Rauschmayer, <a href="http://www.2ality.com/2014/01/eval.html" target="_blank" rel="nofollow">Evaluating JavaScript code via eval() and new Function()</a></li>
</ul>




<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> <a href="https://xiaobaiai.net" target="_blank" rel="nofollow">&#x5C0F;&#x767D;AI.&#x6613;&#x540D;</a>, &#x4F7F;&#x7528;<a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="nofollow">&#x77E5;&#x8BC6;&#x5171;&#x4EAB; 4.0 &#x534F;&#x8BAE;&#x53D1;&#x5E03;</a>&#x53D1;&#x5E03; </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> <i>&#x9875;&#x9762;&#x4FEE;&#x8BA2;&#x4E8E;&#xFF1A;</i> 2019-08-22 16:53:02 </span> </footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="object.html" class="navigation navigation-prev " aria-label="Previous page: 对象">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="array.html" class="navigation navigation-next " aria-label="Next page: 数组">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"函数","level":"1.3.6","depth":2,"next":{"title":"数组","level":"1.3.7","depth":2,"path":"docs/types/array.md","ref":"docs/types/array.md","articles":[]},"previous":{"title":"对象","level":"1.3.5","depth":2,"path":"docs/types/object.md","ref":"docs/types/object.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","chapter-fold","back-to-top-button","search-pro","sharing-plus","myseo","favicon","page-footer-ex","search-pro","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"livereload":{},"page-footer-ex":{"copyright":"<a href='https://xiaobaiai.net' target='_blank'>小白AI.易名</a>, 使用<a href='https://creativecommons.org/licenses/by-sa/4.0/' target='_blank'>知识共享 4.0 协议发布</a>发布","markdown":false,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"<i>页面修订于：</i>"},"search-pro":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"myseo":{"description":"Javascript教程","keywords":"小白AI.易名,xiaobaiai.net,Javascript,入门,教程,博客","titlePrefix":"Javascript教程 - ","titleSuffix":" - 小白AI.易名"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico","appleTouch":"assets/images/apple-touch-icon.png","appleTouchMore":{"120x120":"assets/images/apple-touch-icon-120x120.png","180x180":"assets/images/apple-touch-icon-180x180.png"}},"back-to-top-button":{},"sharing":{"qq":true,"all":["qq","qzone","twitter","weibo","linkedin"],"douban":false,"facebook":true,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"小白AI.易名","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-hans","gitbook":"*","description":"Javascript教程"},"file":{"path":"docs/types/function.md","mtime":"2019-08-22T08:53:02.385Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-08-28T05:00:46.673Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

